local rongxin = fk.CreateSkill {
  name = "emo__rongxin",
}

rongxin:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(rongxin.name) and not player:isNude() and data.from
    and data.from ~= player and (not data.from.dead)
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askToDiscard(player, {
      skill_name = rongxin.name, min_num = 1, max_num = 1, cancelable = true, skip = true, include_equip = true, pattern = ".",
      prompt = "#emo__rongxin-invoke:"..data.from.id,
    })
    if #cards == 1 then
      event:setCostData(self, {tos = {data.from}, cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to_throw = event:getCostData(self).cards
    local cardType = Fk:getCardById(to_throw[1]):getTypeString()
    room:throwCard(to_throw, rongxin.name, player, player)
    local from = data.from---@type ServerPlayer
    for _ = 1, 2 do
      if from:isNude() or from.dead then return false end
      local cards = room:askToDiscard(from, {
        max_num = 1, min_num = 1, cancelable = false, include_equip = true, pattern = ".", skill_name = rongxin.name,
        prompt = "#emo__rongxin-discard:::"..cardType,
      })
      if #cards == 0 then return false end
      if Fk:getCardById(cards[1]):getTypeString() == cardType then
        room:doIndicate(player, {from})
        room:damage{from = player, to = from, damage = 1, damageType = fk.FireDamage}
      end
    end
  end
})

Fk:loadTranslationTable{
  ["emo__rongxin"] = "融心",
  [":emo__rongxin"] = "每当你受到其他角色造成的伤害后，你可以弃置一张牌并令该角色依次弃置两张牌，每弃置一张牌与你弃置的类型相同，你对其造成1点火焰伤害。",
  ["#emo__rongxin-invoke"] = "是否发动“融心”：弃置一张牌，以令 %src 弃置两张牌",
  ["#emo__rongxin-discard"] = "融心：请弃置依次弃置2张牌，若弃置了【%arg】则受到1点火焰伤害",
}

return rongxin
